package com.qst.crop.demo.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 统一数据格式返回类
 */

@Data
public class Result implements Serializable {
    // 状态码
    private Integer code;
    // 状态描述信息
    private String msg;
    // 返回的数据
    private Object data;


    /**
     * 操作成功时返回的数据
     * @param data
     * @return
     */
    public static Result success(Object data){
        Result result = new Result();
        result.setCode(200);
        result.setMsg("");
        result.setData(data);

        return result;
    }

    public static Result success(Integer code, Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg("");
        result.setData(data);

        return result;
    }

    public static Result success(Integer code, Object data, String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);

        return result;
    }

    /**
     * 操作失败时返回的数据
     * @param code
     * @param msg
     * @return
     */
    public static Result fail(Integer code, String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);

        return result;
    }
}

